﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 数据类型转换
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 隐式类型转换
            long l = 45;
            int i = 10;


            // 显示类型转换
            string str = "123";
            Convert.ToInt16(str);// 2个字节，word、short

            Convert.ToInt32(str);// 4个字节，int
            Convert.ToInt64(str); // 8个字节，long

            Convert.ToString(l);

            test();

            string dtstr = FormatDate(DateTime.Now);
            
            dtstr = DateTime.Now.ToString("yyyy-MM-dd");
            Console.WriteLine(dtstr);
            Console.ReadLine();
        }

        public static void test()
        {
            string str = "";
            if(string.IsNullOrEmpty(str))
            {
                Console.WriteLine("字符串没有赋值");
            }
        }

        public static string FormatDate(object objDate)
        {
            if (objDate == null)
            {
                return "";
            }
            DateTime CurrentDate;
            DateTime.TryParse(Convert.ToString(objDate), out CurrentDate);
            return CurrentDate.ToString("yyyy-MM-dd HH:mm");
        }
    }
}
